<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>客户开发计划管理</title>
    <base href=<%=basePath%>
          <%@include file="../common_css.jsp"%>
                  </head>
<body class="childrenBody">
<div class="layui-col-md12">
    <input type="hidden" name="id" value="${customer.id}"/>
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" >
                <div class="layui-form-item layui-row">
                    <div class="layui-col-xs6">
                        <label class="layui-form-label">客户名称</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input"
                                   name="customerName" id="customerName" readonly="readonly" value="${customer.name}">
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <label class="layui-form-label">机会来源</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input"
                                   name="chanceSource" id="chanceSource" readonly="readonly" value="${customer.activity.place}">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-row">
                    <div class="layui-col-xs6">
                        <label class="layui-form-label">手机号码</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input"
                                   name="phone"  lay-verify="required" readonly="readonly" value="${customer.phone}">
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <label class="layui-form-label">微信号</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input"
                                   lay-verify="weixin" name="linkPhone" id="weixin" readonly="readonly" value="${customer.weixin}">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-row">
                    <div class="layui-col-xs6">
                        <label class="layui-form-label">员工姓名</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input"
                                   name="userName" id="userName"  readonly="readonly" value="${customer.user.name}">
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="layui-col-md12">
    <table id="cusDevPlanList" class="layui-table"  lay-filter="cusDevPlans"></table>
</div>

<c:if test="${customer.customerState==2}">
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-normal addNews_btn" lay-event="add">
            <i class="layui-icon">&#xe608;</i>
            添加跟进项
        </a>
        <a class="layui-btn layui-btn-normal addNews_btn" lay-event="success">
            <i class="layui-icon">&#xe608;</i>
            开发成功
        </a>
        <a class="layui-btn layui-btn-normal addNews_btn" lay-event="failed">
            <i class="layui-icon">&#xe608;</i>
            添加失败
        </a>
    </div>
</script>
</c:if>
<script id="cusDevPlanListBar" type="text/html">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
</script>


<script type="text/javascript">
    layui.use(['table','layer'],function(){
        var layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            table = layui.table;

        //计划项数据展示
        var  tableIns = table.render({
            elem: '#cusDevPlanList',
            url : '/cusDevelop/list?id='+$("input[name=id]").val(),
            cellMinWidth : 95,
            method :'post',
            page : true,
            height : "full-125",
            limits : [10,15,20,25],
            limit : 10,
            toolbar: "#toolbarDemo",
            id : "cusDevPlanListTable",
            cols : [[
                {field: "id", title:'编号',fixed:"true"},
                {field: 'stringMode', title: '跟进方式',align:"center"},
                {field: 'content', title: '跟进内容',align:"center"},
                {field: 'stringResult', title: '跟进结果',align:"center"},
                {field: 'createTime', title: '创建时间',align:"center"}
            ]]
        });

        //选项操作（添加计划、开发成功、开发失败）
        table.on("toolbar(cusDevPlans)",function (obj) {
            switch (obj.event) {
                case "add" :
                    openAddOrUpdateCusDevPlanDialog();
                    break;
                case "success":
                    updateSaleChanceDevResult($("input[name='id']").val(),3,4);
                    break;
                case "failed":
                    updateSaleChanceDevResult($("input[name='id']").val(),4,3);
                    break;
            }
        });

        //更新开发状态
        function updateSaleChanceDevResult(id,customerState,oppState) {
            layer.confirm("确认更新机会数据状态?",{icon: 3, title: "客户开发计划管理"},function (index) {
                $.post("/customer/updateCustomerStateAndOpp",{
                    id:id,
                    customerState:customerState,
                    oppState:oppState
                },function (data) {
                    if(data=='success'){
                        layer.msg("机会数据更新成功");
                        layer.closeAll("iframe");
                        // 刷新父页面
                        parent.location.reload();
                    }
                })
            })
        }


        //计划管理（编辑、删除）
        table.on("tool(cusDevPlans)",function (obj) {
            var layEvent = obj.event;
            if(layEvent === "edit"){
                openAddOrUpdateCusDevPlanDialog(obj.data.id);
            }else if(layEvent === "del"){
                layer.confirm("确认删除当前记录?",{icon: 3, title: "客户开发计划管理"},function (index) {
                    $.post(ctx+"/cus_dev_plan/delete",{id:obj.data.id},function (data) {
                        if(data.code==200){
                            layer.msg("删除成功");
                            tableIns.reload();
                        }else{
                            layer.msg(data.msg);
                        }
                    })
                })
            }
        });


        //获取当前用户的计划数据 sid：当前用户 id： 计划数据id
        function openAddOrUpdateCusDevPlanDialog() {
            var title="计划项管理管理-添加计划项";
            var url="/cusDevelop/toCusOpportunityDevInsert?id="+$("input[name='id']").val();
            layui.layer.open({
                title:title,
                type:2,
                area:["600px","500px"],
                maxmin:true,
                content:url
            })
        }
    });

</script>
</body>
</html>